﻿using BLL;
using DAO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using log4net;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        UserBLL userBLL = new UserBLL();
        protected ILog Logger = LogManager.GetLogger(typeof(Form1));

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txtUserName.Focus();

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
                bool flag = false;
                User user = new User
                {
                    UserName = txtUserName.Text,
                    Email = txtEmail.Text,
                    PassWord = txtPass.Text,
                    FirstName = txtFirst.Text,
                    LastName = txtLast.Text
                };
                try
                {
                    userBLL.SaveUser(user,txtPassAgain.Text);
                    flag = true;
                }
                catch (ArgumentNullException ex)
                {
                    MessageBox.Show(ex.ParamName, "Thong bao");
                    //ghi log
                    Logger.Error(ex);
                }
                catch (InvalidCastException ex)
                {
                    MessageBox.Show(ex.Message, "Thong bao");
                    Logger.Error(ex);
                    //ghi log
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Thong bao");
                    Logger.Error(ex);
                    //ghi log
                }
            finally
                {

                }
                if (flag)
                {

                    this.Hide();
                    var form2 = new FeedbackForm(user.UserName);
                    form2.Closed += (s, args) => this.Close();
                    form2.Show();

                }
            
            
            

        }

        
    }
}
